package com.android.support.lib.universal.ui;

import com.android.support.lib.universal.R;
import com.android.support.lib.universal.qr.landscape.CaptureActivity;
import com.android.support.lib.universal.sdk.qq.QqActivity;
import com.android.support.lib.universal.sdk.weibo.WBAuthActivity;
import com.android.support.lib.universal.ui.guide.GuideActivity;
import com.android.support.lib.universal.view.web.WebActivity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import cn.gamehot.mobile.wxapi.WXEntryActivity;

/**
 * Activity之间的跳转
 *
 * @author Administrator
 */
public class UiHelper {

    /**
     * Activity之间的跳转
     *
     * @param context  当前Acitivty
     * @param activtiy 跳转的Activity
     * @param bundle   传递数据数据，可为空 null
     * @param bool     是否销毁当前Acitivity
     */
    public static void toActivity(Context context, Class<?> activtiy,
                                  Bundle bundle, Boolean bool) {
        Intent intent = new Intent(context, activtiy);
        if (bundle != null) {
            intent.putExtras(bundle);
        }
        context.startActivity(intent);
        if (bool) {
            ((Activity) context).finish();
        }
    }

    /**
     * 跳转到引导页
     *
     * @param context
     */
    public static void toGuideActivity(Context context) {
        Intent intent = new Intent(context, GuideActivity.class);
        context.startActivity(intent);
    }

    /**
     * 跳转到启动页
     *
     * @param context
     * @param bool    是否销毁当前Activity
     */
    public static void toStartActivity(Context context, Boolean bool) {
        Intent intent = new Intent(context, StartActivity.class);
        context.startActivity(intent);
        if (bool) {
            ((Activity) context).finish();
        }
    }

    /**
     * @param context      当前Activity
     * @param mainActivity 主Activity,如：MainActivity.class
     * @param bool         是否销毁当前Activity
     */
    public static void toMain(Activity context, Class mainActivity, Boolean bool) {
        //Intent intent = new Intent("android.intent.action.MainActivity");
        Intent intent = new Intent(context, mainActivity);
        context.startActivity(intent);
        context.overridePendingTransition(R.anim.lib_fade_in, R.anim.lib_fade_out);
        if (bool) {
            context.finish();
        }
    }

    /**
     * 跳转webActivity
     *
     * @param context 当前Activity
     * @param url     跳转的URL,不可为空
     * @param title   标题，可为null
     */
    public static void toWebActivivy(Context context, String url, String title) {
        Bundle bundle = new Bundle();
        bundle.putString("url", url);
        if (title != null) {
            bundle.putString("title", title);
        }
        Intent intent = new Intent();
        intent.setClass(context, WebActivity.class);
        intent.putExtras(bundle);
        context.startActivity(intent);
    }

    /**
     * 跳转到横屏二维码，需重写onActivityResult()方法
     *
     * @param context
     */
    public static void toLandscapeCaptureActivity(Activity context, int requestCode) {
        Intent intent = new Intent();
        // 记录当前跳转的Activity
        intent.putExtra("class", context.getClass());
        intent.setClass(context, CaptureActivity.class);
        context.startActivityForResult(intent, requestCode);
    }

    /**
     * 跳转到竖屏二维码，需重写onActivityResult()方法
     *
     * @param context
     */
    public static void toPortraitCaptureActivity(Activity context, int requestCode) {
        Intent intent = new Intent();
        // 记录当前跳转的Activity
        intent.putExtra("class", context.getClass());
        intent.setClass(context, com.android.support.lib.universal.qr.portrait.CaptureActivity.class);
        context.startActivityForResult(intent, requestCode);
    }

    /**
     * 跳转到QQ授权界面
     *
     * @param context
     */
    public static void toQqActvity(Context context) {
        Intent intent = new Intent();
        intent.setClass(context, QqActivity.class);
        context.startActivity(intent);
    }

    /**
     * 跳转到微博授权界面
     *
     * @param context
     */
    public static void toWBActivity(Context context) {
        Intent intent = new Intent();
        intent.setClass(context, WBAuthActivity.class);
        context.startActivity(intent);
    }

    /**
     * 跳转到微信授权界面
     *
     * @param context
     */
    public static void toWeixin(Context context) {
        Intent intent = new Intent(context, WXEntryActivity.class);
        Bundle bundle = new Bundle();
        // 标识，微信授权登录
        bundle.putString("LOGIN", "00");
        intent.putExtras(bundle);
        context.startActivity(intent);
    }

    /**
     * 跳转到桌面
     *
     * @param context
     */
    public void toDesktop(Context context) {
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_HOME);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
    }

    /**
     * 把当前任务放入后台，在activity界面调用，这个方法会返回到进入应用之前的那个界面
     *
     * @param activity
     */
    public void toTask(Activity activity) {
        activity.moveTaskToBack(true);
    }

}